/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.dw.lidejia.hadooptotalsort.mr;

import com.snda.dw.lidejia.hadooptotalsort.meta.SortKeyMeta;
import com.snda.dw.lidejia.hadooptotalsort.meta.SortKeyMetaPool;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapred.JobConf;

/**
 *
 * @author lidejia
 */
public class SortKeysExtractor {

    private List<SortKeyMeta> metas;

    public SortKeysExtractor() {
        metas = SortKeyMetaPool.getInstance().getMetas();
    }

    public List<WritableComparable> extract(String line) {
        // split the columns
        String[] columns = line.split("\t");
        // result
        List<WritableComparable> result = new ArrayList<WritableComparable>(columns.length);
        for (SortKeyMeta meta : metas) {
            result.add(meta.parse(columns));
        }
        return result;
    }
}
